# coding=utf8
from libs.dbs import MongoBase

model_res_classify = MongoBase('ResourceClassify')


def get_classify():
    classify = dict()
    for c in model_res_classify.coll.find():
        classify[c['ClassifyName']] = c['_id']
    return classify


def add_classify(classify):
    for classify in classify.keys():
        model_res_classify.coll.insert_one({
            'ClassifyName': classify
        })


def add_nx_classify(classify_name):
    classify = model_res_classify.coll.find_one({
        'ClassifyName': classify_name
    })
    if classify is None:
        res = model_res_classify.coll.insert_one({
            'ClassifyName': classify_name
        })
        return res.inserted_id
    else:
        return classify['_id']
